package com.unionpay.upyzt.model;

import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.net.APIResource;
import com.unionpay.upyzt.net.RequestOptions;
import com.unionpay.upyzt.resp.AllocationResp;
import lombok.experimental.Accessors;

import java.util.Map;

@Accessors(chain = true)
public class Allocation extends APIResource {

    /**
     * 分账
     *
     * @param params 请求参数
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp create(Map<String, Object> params) throws UpyztException {
        return create(params, null);
    }

    /**
     * 分账
     *
     * @param params  请求参数
     * @param options 参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp create(Map<String, Object> params, RequestOptions options) throws UpyztException {
        return APIResource.request(RequestMethod.POST, classURL(Allocation.class), params, AllocationResp.class, options);
    }

    /**
     * 分账订单查询（系统订单号）
     *
     * @param id 系统订单号
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp retrieveById(String id) throws UpyztException {
        return retrieveById(id, null);
    }

    /**
     * 分账订单查询（系统订单号）
     *
     * @param id      系统订单号
     * @param options 参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp retrieveById(String id, RequestOptions options) throws UpyztException {
        return APIResource.request(RequestMethod.GET, instanceURL(Allocation.class, id), null, AllocationResp.class, options);
    }

    /**
     * 分账订单查询（平台订单号）
     *
     * @param outOrderNo 平台订单号
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp retrieveByOutOrderNo(String outOrderNo) throws UpyztException {
        return retrieveByOutOrderNo(outOrderNo, null);
    }

    /**
     * 分账订单查询（平台订单号）
     *
     * @param outOrderNo 平台订单号
     * @param options    参数选项
     * @return 返回参数
     * @throws UpyztException 异常
     */
    public static AllocationResp retrieveByOutOrderNo(String outOrderNo, RequestOptions options) throws UpyztException {
        return APIResource.request(RequestMethod.GET, instanceURL(Allocation.class, "_by_out_order_no", outOrderNo), null, AllocationResp.class, options);
    }

}
